package org.example.acm;

import java.util.*;
import java.util.stream.Collectors;

public class PokerStraightSolution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] pokers = scanner.nextLine().split(" ");
        List<List<String>> res = getStraightList(pokers);
        if (res.isEmpty()) {
            System.out.println("No");
        } else {
            res.forEach(straight->System.out.println(String.join(" ", straight)));
        }
        scanner.close();
    }

    private static List<List<String>> getStraightList(String[] pokers) {
        Map<String, Integer> map = new HashMap<>();
        //2不可能组成顺子
        map.put("3", 3);
        map.put("4", 4);
        map.put("5", 5);
        map.put("6", 6);
        map.put("7", 7);
        map.put("8", 8);
        map.put("9", 9);
        map.put("10", 10);
        map.put("J", 11);
        map.put("Q", 12);
        map.put("K", 13);
        map.put("A", 14);
        List<String> pokerList = Arrays.stream(pokers)
                .filter(s -> !s.equals("2"))
                .sorted((a,b)->map.get(a)-map.get(b))
                .collect(Collectors.toList());
        List<List<String>> res = new ArrayList<>();
        List<String> straight = new ArrayList<>();
        straight.add(pokerList.get(0));
        res.add(straight);
        for (int i=1;i<pokerList.size();i++) {
            String poker = pokerList.get(i);
            boolean add = false;
            for (List<String> item: res) {
                String lastPoker = item.get(item.size()-1);
                if (map.get(poker) - map.get(lastPoker) == 1) {
                    item.add(poker);
                    add = true;
                    break;
                }
            }
            if (!add) {
                List<String> newStraight = new ArrayList<>();
                newStraight.add(poker);
                res.add(newStraight);
            }
        }
        return res.stream().filter(item -> item.size() >= 5).collect(Collectors.toList());
    }
}
